package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.CmsMember;
import com.example.demo.common.Response;
import com.example.demo.service.CmsMemberService;

@RestController
@RequestMapping("/member")
public class CmsMemberController {

	@Autowired
	private CmsMemberService cmsMemberService;
	
	@GetMapping("/selectAll")
	public Response<List<CmsMember>> selectAll() {
		List<CmsMember> list = cmsMemberService.selectAll();
		return Response.ok(list);
	}
	
	@PostMapping("/selectById")
	public Response<CmsMember> selectById(String id)
	{
		CmsMember cs =cmsMemberService.selectById(id);
		return Response.ok(cs);
	}
	
	@DeleteMapping("/deleteById")
	public Response<String> deleteById(String id)
	{
		int count = cmsMemberService.deleteById(id);
		if (count == -1) {
			return Response.error("删除失败！！！");
		}
		return Response.ok("成功删除了："+count+"个会员！！！");
	}

	@DeleteMapping("/deleteByIds")
	public Response<String> deleteByIds(String[] ids)
	{
		int count = cmsMemberService.batchDeleteByIds(ids);
		if (count ==0) {
			return Response.error("删除失败！！！");
		}
		return Response.ok("成功删除"+count+"条链接信息！！！");
	}
	
	@PostMapping("/saveOrUpdate")
	public Response<String> saveOrUpdate(CmsMember cmsMember) {
	int count=	cmsMemberService.saveOrUpdate(cmsMember);
	if (count==-1) {
		return Response.error("保存失败！！！");
	}
		return Response.ok("保存成功");
	}
}






